package com.zkyc.framework.common.mapper;

import com.zkyc.framework.common.pojo.Menu;
import com.zkyc.framework.common.pojo.Right;
import com.zkyc.framework.common.pojo.UserRefRole;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (SystemUserRefRole)表数据库访问层
 *
 * @author wj
 * @since 2022-06-01 10:01:37
 */
@Mapper
public interface UserRefRoleMapper extends BaseMapper<UserRefRole> {

    @Select({"<script>" +
            " select distinct d.* from system_user_ref_role a,system_website_ref_role b," +
            "system_role_ref_right c,system_right d,system_role e" +
            " where a.role_id=b.role_id" +
            "    and b.website_id=#{websiteId}" +
            "    and c.role_id=a.role_id" +
            "    and d.id=c.right_id" +
            "    and d.is_deleted=0" +
            "    and e.id=a.role_id " +
            "    and e.`status`=1"+
            "    and a.user_id=#{userId}" +
            "    order by d.sort" +
            "</script>"
    })
    public List<Right> getUserWebRight(@Param("userId") String userId,@Param("websiteId") Integer websiteId);

    @Select("select role_id from system_user_ref_role where user_id = #{userId}")
    List<String> selectRoleList(String userId);



    @Select({"<script>" +
            "SELECT DISTINCT" +
            " c.*  " +
            "FROM " +
            " system_right c, " +
            " ( " +
            " SELECT DISTINCT " +
            "  a.id, " +
            "  a.parent_id  " +
            " FROM " +
            "  system_right a  " +
            " WHERE " +
            " a.id IN (${rightIdList})) b  " +
            "WHERE " +
            " c.id = b.id  " +
            " OR c.id = b.parent_id " +
            " and c.is_deleted=0 " +
            " ORDER BY c.sort " +
            " ",
            "</script>"
    })
    List<Right> getRightAndParent(@Param("rightIdList") String  rightIdList );




}

